﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
//using MangoChat;
//using QLPKWeb.BussinessDelegate.ChatDelegate;
using QLPKWeb.BussinessDelegate.PhanQuyen;
//using MangoService;
//using MangoService.SQLStorage;
using System.Configuration;
//using OracleDataProvider;

namespace QLPKWeb
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Authentication", action = "login", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            //if (bool.Parse(ConfigurationManager.AppSettings["UseSqlProvider"]))
            //{
            //    Service.Instance.Storage = new SQLServerStorageProvider();
            //}
            //else if (bool.Parse(ConfigurationManager.AppSettings["UseOracleProvider"]))
            //{
            //    Service.Instance.Storage = new OracleStorageProvider(ConfigurationManager.AppSettings["MangoServiceOracleConnectionString"]);
            //}
            
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            // Bắc đầu chat Services
            //ChatService.Start();
            // Gán Delegate cho việc nhận thông tin User
            //ChatService.OnUserInfoRequired += new Action<OnUserInfoRequiredEventArgs>
            //                 (ChatService_OnUserInfoRequired);
        }

        //void ChatService_OnUserInfoRequired(OnUserInfoRequiredEventArgs obj)
        //{
        //    UsersServiceDelegate UsersServiceDelegate = new UsersServiceDelegate();
        //    var dbus = UsersServiceDelegate.GetUsersById(obj.UserId);
        // //   var dbUser = FakeDAL.GetUserById(obj.UserId);
        //    var user = new MangoChat.User 
        //    {
        //        UserId = dbus.ID.ToString(),
        //        Username = dbus.UserName
        //    };
        //    obj.User = user;
        //}

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}